package st.shadow.library.core.util.utilcode.util;

import android.content.res.AssetManager;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by zhangyu on 2017/8/21.
 */

public class AssetsUtils {
    /**
     * 读取assets下的txt文件，返回utf-8 String
     * @param fileName 包括后缀
     * @return
     */
    public static String readAssetsTxt(String fileName){
        StringBuilder sb = new StringBuilder();
        AssetManager am = Utils.getContext().getAssets();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    am.open(fileName)));
            String next;
            while (null != (next = br.readLine())) {
                sb.append(next);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            sb.delete(0, sb.length());
        }
        return sb.toString().trim();
    }
}
